package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	/**
	 * 查询用户可以购买的声音的信息: 一次最多购买50集
	 * @param trackId
	 * @return
	 */
	@GuiguLogin
	@GetMapping(value = "findUserTrackPaidList/{trackId}")
	public Result findUserTrackPaidList(@PathVariable(value = "trackId") Long trackId){
		return Result.ok(trackInfoService.findUserTrackPaidList(trackId));
	}
	/**
	 * 1110 查询声音的统计数据
	 * @param trackId
	 * @return
	 */
	@GetMapping("getTrackStatVo/{trackId}")
	public Result getTrackStatVo(@PathVariable("trackId") Long trackId){
		return Result.ok(trackInfoService.getTrackStatVo(trackId));
	}

	/**
	 * 查询指定专辑的分页声音列表
	 * @param page
	 * @param limit
	 * @param albumId
	 * @return
	 */
	@GuiguLogin
	@GetMapping("/findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result findAlbumTrackPage(@PathVariable Long page, @PathVariable Long limit, @PathVariable Long albumId){
		return Result.ok(trackInfoService.findAlbumTrackPage(new Page<>(page, limit), albumId));
	}

	/**
	 * 声音的上传
	 * @param file
	 * @return JSONObject
	 */
    @PostMapping("/uploadTrack")
	public Result uploadTrack(@RequestParam MultipartFile file){
		return Result.ok(trackInfoService.uploadTrack(file));
	}

	/**
	 * 声音的保存
	 * @param trackInfoVo
	 * @return
	 */
	// @GuiguLogin
	@PostMapping("/saveTrackInfo")
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.saveTrackInfo(trackInfoVo);
		return Result.ok();
	}

	/**
	 * 查询当前用户的分页声音列表
	 * @param trackInfoQuery
	 * @return
	 */
	@GuiguLogin
	@PostMapping("/findUserTrackPage/{page}/{limit}")
	public Result findUserAlbumPage(@PathVariable Long page, @PathVariable Long limit, @RequestBody TrackInfoQuery trackInfoQuery){
		return Result.ok(trackInfoService.findUserAlbumPage(new Page<>(page, limit), trackInfoQuery));
	}

	/**
	 * 根据专辑Id删除声音
	 * @param trackId
	 * @return
	 */
	@GuiguLogin
	@DeleteMapping("/removeTrackInfo/{trackId}")
	public Result removeTrackInfo(@PathVariable(value = "trackId") Long trackId){
		trackInfoService.removeTrackInfo(trackId);
		return Result.ok();
	}
	/**
	 * 修改数据时回显数据
	 * @param trackId
	 * @return
	 */
	@GuiguLogin
	@GetMapping(value = "/getTrackInfo/{trackId}")
	public Result getTrackInfo(@PathVariable(value = "trackId") Long trackId){
		return Result.ok(trackInfoService.getTrackInfo(trackId));
	}

	/**
	 * 修改声音
	 * @param trackId
	 * @param trackInfoVo
	 * @return
	 */
	@GuiguLogin
	@PutMapping("/updateTrackInfo/{trackId}")
	public Result updateTrackInfo(@PathVariable Long trackId, @RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.updateTrackInfo(trackId, trackInfoVo);
		return Result.ok();
	}

}

